import 'package:get/get.dart';
import 'package:xingsu/util/cache_util.dart';
import 'package:xingsu/util/use_preferences.dart';

class MineViewModel extends GetxController {
  final cache = "".obs;
  final themeMode = "".obs;
  final isLogin = false.obs;

  @override
  void onInit() {
    super.onInit();

    cache.value = getMemoryImageCache();
    isLogin.value = UserPreferences.getIsLogin();
    getThemeModelDesc();
  }

  void getThemeModelDesc() {
    int theme = UserPreferences.getThemeMode();
    if (theme == 0) {
      themeMode.value = "跟随系统";
    } else if (theme == 1) {
      themeMode.value = "关闭";
    } else {
      themeMode.value = "开启";
    }
  }

  void changeLogin() {
    isLogin.value = UserPreferences.getIsLogin();
  }

  void clearCache() {
    clearImageCache();
    Future.delayed(const Duration(milliseconds: 500), () {
      cache.value = getMemoryImageCache();
    });
  }
}
